import { createAndInitilalizeTable } from '@/components/table/lib';
import { ready, assert, getApiPath } from '@/lib/utils.ts';

import {
    tf,
    questionMarkHeaderComponentParams,
    auditStatusCol
} from '@/components/table/lib';

function initializeTable(url: string) {
    const table_elem = document.getElementById("table");
    assert(table_elem, "Element with ID 'table' not found");
        
    createAndInitilalizeTable(
        url,
        table_elem,
        {
            columnDefs: [
                {
                    ...tf("version", "版本号"),
                    width: 110
                },
                {
                    ...tf("time", "创建时间"),
                    type: "date"
                },
                {
                    ...tf("date_new_drug_registration_submission", "提交新药注册申请日期"),
                    type: "date"
                },
                {
                    ...tf("date_investigational_drug_preparation_completion",
                        "提交新药注册申请日期"),
                    type: "date"
                },
                {
                    ...tf("filing_location", "归档地点"),
                    width: 150
                },
                {
                    ...tf("note", "备注"),
                    minWidth: 200,
                    flex: 1,
                },
                {
                    field: "is_draft",
                    headerName: gettext("是否为草稿"),
                    headerComponentParams: questionMarkHeaderComponentParams,
                    headerTooltip: '若不是草稿，相关人员能够对此事项进行审核',
                    pinned: 'right',
                    width: 140,
                },
                auditStatusCol({})
            ]
        }
    );
}

(function () {
    ready(() => {
        initializeTable(getApiPath());
    });
})();

